package com.edais.util.youdun;

import java.net.URLEncoder;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.edais.util.CommonUtil;
import com.edais.util.ThirdPartyEnvUtil;
import com.edais.util.RSAThirdParty.RSA;


public class UdRequestUtil {
	private static final Log logger = LogFactory.getLog(UdRequestUtil.class);
	/**
	 * 根据接口名字调用第三方有盾接口
	 * @author zhouyj
	 */
	public static String sendUd(String interfaceName,Map<String,String> paramMap) throws Exception {
		String udResult = "";
		try {
			String requestParam = "keyRandom=KEY_RANDOM";
			String publicKeyParam="";
			logger.info("-------------------------------------javaservice调用thirdParty-开始对接有盾-接口："+interfaceName+",参数："+paramMap);
			try {
				publicKeyParam = RSA.getPublick_Key_Encrypt(paramMap);
				requestParam = requestParam.replace("KEY_RANDOM",
						URLEncoder.encode(publicKeyParam, "utf-8"));
			} catch (Exception e) {
				logger.debug("-------------------------------------javaservice调用thirdParty-公钥加密串出现异常：" + e);
			}

			String thirdPartyUrl = ThirdPartyEnvUtil.getValue("thirdPartyPath");;
			udResult = CommonUtil.sendPostByHttp(thirdPartyUrl+interfaceName, requestParam);
			
			logger.info("-------------------------------------javaservice调用thirdParty-对接有盾结束,thirdParty返回："+udResult);
		} catch (Exception e) {
			e.printStackTrace();
			logger.info("-------------------------------------javaservice调用thirdParty-对接有盾出现异常："+e.getMessage());
		}
		return udResult;
	}
	
}
